<?php
/**
 * Created by PhpStorm.
 * User: lgy
 * Date: 2018/6/30
 * Time: 20:55
 */

namespace app\admin\model;
use think\Db;

class Shop
{
	//获取全部事务
	public static function getShop($params){
		$limit = 10;
		$params['page'] = isset($params['page'])?$params['page']:1;
		$start = $params['page'] * $limit - 10;
		$condition = [
			's.status'=>1
		];
		$field = [
			's.id AS shop_id,s.name,s.platform,s.head_id,s.service_id,s.style,s.address,s.content,s.create_time,s.update_time,s.status',
			'ah.nickname AS head_name',
			'as.nickname AS service_name',
		];
		$join = [
			['dbkj_admin ah','ah.id=s.initiator_id','LEFT'],
			['dbkj_admin as','as.id=s.receiver_id','LEFT'],
		];
		$result = Db::table('dbkj_shop')->alias('s')->field($field)->join($join)->where($condition)->limit($start,$limit)->select();
		return $result;
	}
	//添加事务
	public static function addShop($params){
		$insert = [
			'name'=>$params['name'],
			'platform'=>$params['platform'],
			'address'=>$params['address'],
			'head_id'=>$params['head_id'],
			'service_id'=>$params['service_id'],
			'style'=>$params['style'],
			'content'=>$params['content'],
			'create_time'=>time(),
			'update_time'=>time(),
			'status'=>1
		];
		$result = Db::table('dbkj_shop')->insert($insert);
		return $result;
	}
}